<template>
<view class="uni-input-num">
		<view class="uni-timesec">
			<span class="uni-button-b" @tap="stopTime()">暂停</span>
			<span>{{hour}}</span>:<span>{{min}}</span>:<span>{{sec}}</span>
			<span class="uni-button-b" @tap="reStartTime()">继续</span>
			</view>
		<view v-for="(item,index) in title" :key="index" class="uni-title">{{item.title}}</view>
		<view class="uni-errTitle-bdx">本次答题记录：<span>查看历史记录需<span @tap="login()" class="uni-login">登录</span></span>
		<view class="uni-errBody" v-for="(item,index) in resultList" :key="index">
			<view :style="{color:item.result == item.trueResult?'green':'red'}">
				题目：{{item.tit}} 答案：{{item.result}} 耗时：{{item.hour}}时{{item.min}}分{{item.sec}}秒</view>
			</view>
		</view>
		<view class="uni-result">请输入答案：{{uresult}}</view>
		<view class="uni-borader">
			<view class="uni-marginTop-small ">
				<button @tap="addNum('<')" class="uni-btn-larger">{{dayu}}</button>
				<button @tap="addNum('=')" class="uni-btn-larger">{{dengyu}}</button>
				<button @tap="addNum('>')" class="uni-btn-larger">{{xiaoyu}}</button>
			</view>
			
			<view class="uni-marginTop-small">
				<button @tap="upNum()" class="uni-badge-success">提交答案</button>
				<button @tap="delNum()" class="uni-badge-warning">删除答案</button>
			</view>
		</view>
	</view>
</template>

 <script>
		import {saveEasyNum} from '@/api/work/study.js'
	export default {
		name:"bdxInput",
		data() {
			return {
				dayu:'<',
				dengyu:'=',
				xiaoyu:'>',
						timeStatus:'false',
						hour:'00',
						min:'00',
						sec:'00',
						uresult:'',
						resultList:[],
						timer:{},
						nowResult:{},
						saveResult:[],
						i: 0,
						};
					},
					props:['title'],
					mounted() {
						this.startTime()
					},
			
					methods:{
						stopTime(){
							if(this.timeStatus == 'false'){
								clearInterval(this.timer)
								this.timeStatus='true'
							}
						},
						reStartTime(){
							if(this.timeStatus == 'true'){
								this.timer = setInterval(this.start,1000)
								this.timeStatus='false'
							}
						},
						login(){
							uni.navigateTo({
								url:'/pages/login'
							})
						},
						startTime(){
							clearInterval(this.timer)		
							this.timer = setInterval(this.start,1000)
						},
						start(){
							this.i++
							this.sec = this.doubleNum(this.i%60)
							this.min = this.doubleNum(parseInt(this.i / 60) %60)
							this.hour = this.doubleNum(parseInt(this.i / 3600))
						},
						doubleNum(n){
							if(n < 10){
							   return '0' + n;
							}else{
							    return n;
							}
						},
						upNum(){
							if(this.uresult != ''){
								let status = this.$store.state.tableStatus;   // 重新赋值
							    this.$store.commit("changeStatus", !status);
								 this.nowResult ={
									tit : this.title[0].title,
									result : this.uresult,
									hour : this.hour,
									min : this.min,
									sec : this.sec,
									trueResult : this.title[0].result
								}
								this.saveResult = {
									title : this.title[0].title,
									result : this.uresult,
									remark : '耗时:'+this.hour+'时'+this.min+'分'+this.sec+'秒',
									statu: this.uresult == this.nowResult.trueResult? 1:0
								}
								saveEasyNum(this.saveResult).then(resp=>{
									
								})
								this.resultList.push(this.nowResult)
								this.i= 0
								this.sec= '00' 
								this.min= '00' 
								this.hour= '00'
								this.uresult = ''
								this.startTime()
							}
						},
						addNum(val){
							this.uresult = val		
						},
						
						delNum(){
							this.uresult = ''
						}
					},
					}
 			</script>
			
			<style lang="scss">
			
			</style>